package com.sc.nft.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.sc.nft.dao.MallOrderDao;
import com.sc.nft.dao.MallOrderProductDao;
import com.sc.nft.entity.MallOrderProduct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.service.MallOrderProductService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ip商品订单关联商品表服务接口实现
 *
 * @author Sun
 * @since 2023-05-09 10:47:10
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class MallOrderProductServiceImpl implements MallOrderProductService {
    private final MallOrderProductDao mallOrderProductDao;
    private final MallOrderDao mallOrderDao;

    /**
     * 根据用户id和活动id查询用户购买数量（玛特APP ）
     * @param userId
     * @param mallActivityId
     * @return
     */
    @Override
    public Integer getUserBuyCountByUserIdAndActivityId(Long userId, Long mallActivityId) {
        return mallOrderDao.getListByUserIdAndMallActivityIdAndStatusAndRefundStatus(userId, mallActivityId);
    }

    /**
     * 根据小程序用户id和活动id查询用户购买数量（商城小程序 ）
     *
     * @param miniUserId
     * @param mallActivityId
     * @return
     */
    @Override
    public Integer getMiniUserBuyCountByUserIdAndActivityId(Long miniUserId, Long mallActivityId) {
        return mallOrderDao.getMiniUserBuyCountByUserIdAndActivityId(miniUserId, mallActivityId);
    }

    @Override
    public List<MallOrderProduct> getListByOrderId(Long orderId) {
        return mallOrderProductDao.getListByOrderId(orderId);
    }

    @Override
    public String getProductTitleByOrderId(Long order) {
        List<MallOrderProduct> list = getListByOrderId(order);
        if(list.size()>0){
            return StrUtil.format("{}={}件商品",list.get(0).getProductName(),list.get(0).getProductNum());
        }
        return "";
    }

    @Override
    public MallOrderProduct getById(Long id) {
        return mallOrderProductDao.getById(id);
    }

    @Override
    public MallOrderProduct getOneByOrderIdAndOrderProductId(Long orderId, Long orderProductId) {
        return mallOrderProductDao.getOneByOrderIdAndOrderProductId(orderId, orderProductId);
    }
}